package bstsetcode;

/**
 * @author noob
 * @version 1.0
 * @date 2021/3/13 18:46
 */
public class SelectionSort {

    public SelectionSort() {
    }

    public static void sort(int[] data){

        for (int i = 0; i < data.length; i++) {
            int minIndex = i;
            for (int j = i; j < data.length; j++) { // 从i开始
                if(data[j] < data[minIndex]){
                    minIndex = j;
                }
            }
            exchange(data,i,minIndex);

        }

    }

    private static void exchange(int[] data, int i, int j) {
        int temp = data[i];
        data[i] =data[j];
        data[j] = temp;
    }



    public static void main(String[] args) {
        int[] data2 = {6,4,2,3,2,1,5,5,};
        SelectionSort.sort(data2);
        for (int n:data2){
            System.out.print(n +" ");
        }
        System.out.println();

    }


}
